package com.yanqu.road.server.cmd.newmonopolymkt.res;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.newmonopolymkt.NewMonopolyMarketProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.CmdApi;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.systemgroup.newmonopolymarket.NewMonopolyMarketMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@CmdApi(reqMsg = NewMonopolyMarketProto.NewMonopolyMarketEnterResGrabPointReqMsg.class, respMsg = NewMonopolyMarketProto.NewMonopolyMarketEnterResGrabPointRespMsg.class)
@Cmd(code = GameProtocol.S_NEW_MONOPOLY_MARKET_RES_GRAB_ENTER_SEAT, desc = "进入资源争夺战的座位")
public class NewMonopolyMarketResGrabEnterSeatCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        NewMonopolyMarketProto.NewMonopolyMarketEnterResGrabPointReqMsg req = NewMonopolyMarketProto.NewMonopolyMarketEnterResGrabPointReqMsg.parseFrom(packet.getBytes());
        if(!NewMonopolyMarketMgr.canEnterSystem(player)){
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
            return;
        }
        if(!NewMonopolyMarketMgr.isSystemOpenTime(req.getResType())){
            ret = GameErrorCode.E_NEW_MONOPOLY_MARKET_SYSTEM_NO_OPEN;
            return;
        }
        NewMonopolyMarketMgr.sendAppointActivityPacket(player.getUserId(), CrossProtocol.C_CROSS_NEW_MONOPOLY_MARKET_RES_GRAB_ENTER_SEAT, req.toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            NewMonopolyMarketProto.NewMonopolyMarketEnterResGrabPointRespMsg.Builder builder = NewMonopolyMarketProto.NewMonopolyMarketEnterResGrabPointRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_NEW_MONOPOLY_MARKET_RES_GRAB_ENTER_SEAT, builder);
        }
    }

}
